package com.wry.wry_test.algorithm;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: wangrongyi
 * @Date: 2024/11/26 13:39
 * @Description:
 */
public class Day15 {
    public static int solution(int a, int b) {
        // write code here
        List<Integer> numList = new LinkedList<>();
        while (a != 0) {
            numList.add(a % 10);
            a /= 10;
        }
        Collections.reverse(numList);
        int calNum = b;
        while (calNum / 10 != 0) {
            calNum /= 10;
        }
        int index = 0;
        for (; index < numList.size(); index++) {
            if (calNum > numList.get(index)) {
                numList.add(index, b);
                break;
            }
        }
        if (index == numList.size()) {
            numList.add(b);
        }
        StringBuilder res = new StringBuilder();
        for (Integer i : numList) {
            res.append(i);
        }

        return Integer.parseInt(res.toString());
    }

    public static void main(String[] args) {
        System.out.println(solution(76543, 4) == 765443);
        System.out.println(solution(1, 0) == 10);
        System.out.println(solution(44, 5) == 544);
        System.out.println(solution(666, 6) == 6666);
        System.out.println(solution(9, 15) == 915);
        System.out.println(solution(17, 1) == 171);
    }

}
